<template>
  <div id="demand">
    <div class="body">
      <div class="title">
        <span>3<i style="opacity: .5;">/4</i></span>
        <span>
          <van-icon name="records-o" size="22" color="#1989fa;"/>&nbsp;假肢需求与期望
        </span>
      </div>
      <van-divider />
      <form>
        <div class="one">
          <h3>
            <span class="iconfont icon-bitian" style="color: #ec6661;"></span>
            <i style="opacity: .5;">[多选题]</i>
            您希望假肢具备哪些功能?
            <van-tag type="warning" v-if="message[0].bool">您未完成此项</van-tag>
          </h3>
          <van-checkbox-group v-model="message[0].data">
            <van-checkbox name="1" shape="square">精准动作能力</van-checkbox>
            <van-checkbox name="2" shape="square">轻便耐用</van-checkbox>
            <van-checkbox name="3" shape="square">高度可定制</van-checkbox>
            <van-checkbox name="4" shape="square">感知反馈功能</van-checkbox>
            <van-checkbox name="5" shape="square">其他</van-checkbox>
          </van-checkbox-group>
        </div>
        <div class="two">
          <h3>
            <span class="iconfont icon-bitian" style="color: #ec6661;"></span>
            <i style="opacity: .5;">[多选题]</i>
            您对假肢的外观有何期望
            <van-tag type="warning" v-if="message[1].bool">您未完成此项</van-tag>
          </h3>
          <van-checkbox-group v-model="message[1].data">
            <van-checkbox name="1" shape="square">尽可能接近真实肢体</van-checkbox>
            <van-checkbox name="2" shape="square">简洁实用</van-checkbox>
            <van-checkbox name="3" shape="square">其他</van-checkbox>
          </van-checkbox-group>
        </div>
        <div class="three">
          <h3>
            <span class="iconfont icon-bitian" style="color: #ec6661;"></span>
            <i style="opacity: .5;">[单选题]</i>
            您是否考虑购买或更换假肢?
            <van-tag type="warning" v-if="message[2].bool">您未完成此项</van-tag>
          </h3>
          <van-radio-group v-model="message[2].data" direction="horizontal" class="three-radio-group">
            <van-radio name="1">是</van-radio>
            <van-radio name="2">否</van-radio>
          </van-radio-group>
        </div>
        <div class="four">
          <h3>
            <span class="iconfont icon-bitian" style="color: #ec6661;"></span>
            <i style="opacity: .5;">[多选题]</i>
            您认为购买或更换假肢的最大障碍是什么?
            <van-tag type="warning" v-if="message[3].bool">您未完成此项</van-tag>
          </h3>
          <van-checkbox-group v-model="message[3].data">
            <van-checkbox name="1" shape="square">价格过高</van-checkbox>
            <van-checkbox name="2" shape="square">没有合适的型号或功能</van-checkbox>
            <van-checkbox name="3" shape="square">定制过程繁琐</van-checkbox>
            <van-checkbox name="4" shape="square">其他</van-checkbox>
          </van-checkbox-group>
        </div>
        <div class="five">
          <h3>
            <span class="iconfont icon-bitian" style="color: #ec6661;"></span>
            <i style="opacity: .5;">[单选题]</i>
            你能接受的假肢价格区间是?
            <van-tag type="warning" v-if="message[4].bool">您未完成此项</van-tag>
          </h3>
          <van-radio-group v-model="message[4].data" class="five-radio-group">
            <van-radio name="1">1000-2500</van-radio>
            <van-radio name="2">2500-5000</van-radio>
            <van-radio name="3">5000-8000</van-radio>
            <van-radio name="4">10000以上</van-radio>
          </van-radio-group>
        </div>
      </form>
    </div>
    <div class="tapBar">
      <div class="tapBarBox" style="border-right: 1px solid rgba(0, 0, 0,.2);color: #1989fa;">
          <button @click="$router.back()">上一页</button>
        </div>
      <div class="tapBarBox">
        <button :disabled="isdisabled" @click="skip" type="buttom">下一页</button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'demandPage',
  data () {
    return {
      message: [
        { data: [], bool: false },
        { data: [], bool: false },
        { data: '', bool: false },
        { data: [], bool: false },
        { data: '', bool: false }
      ],
      isSkip: [],
      isdisabled: false,
      timer: null
    }
  },
  methods: {
    skip () {
      this.isSkip = JSON.parse(localStorage.getItem('demand'))
      if (this.isSkip === null) {
        this.message.forEach(item => {
          item.bool = true
        })
        this.isdisabled = true
        this.timer = setTimeout(() => {
          this.message.forEach(item => {
            item.bool = false
          })
          this.isdisabled = false
        }, 2000)
        return
      }

      if (this.message.find((item) => item.data.length === 0)) {
        this.isdisabled = true
        this.message.forEach(item => {
          if (item.data.length === 0) {
            item.bool = true
          }
        })

        this.timer = setTimeout(() => {
          this.message.forEach(item => {
            item.bool = false
          })
          this.isdisabled = false
        }, 2000)
        return
      }

      this.$router.push('/survey/support')
    }
  },
  created () {
    if (localStorage.getItem('demand')) this.message = JSON.parse(localStorage.getItem('demand'))
  },
  watch: {
    message: {
      deep: true,
      handler (newVal) {
        localStorage.setItem('demand', JSON.stringify(newVal))
      }
    }
  }
}
</script>

<style scoped>
form .one,
form .two,
form .three,
form .four{
margin-bottom: 15px;
}
.three-radio-group{
  display: flex;
  justify-content: space-around;
}
.five-radio-group{
  padding: 0 20px;
}
</style>
